<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>异步请求</title>
    <script src="js/jquery-1.4.4.min.js"></script>

</head>
<body>
    <input type="button" value="get请求" onclick="clickGet()">
    <input type="button" value="post请求" onclick="clickPost()">

</body>
<script type="text/javascript">
    function  clickGet(){
        var param={"id":1,"username":"张三","sex":"男"};
        //发起异步请求
        $.ajax({
            type:"get",
            url:"/json/testGet",
            contentType: "application/json",
            success:function (data){
                console.log(data)
                alert(data)
            },
            error:function (data){
                console.log("失败了")
            }

        });
    }
    function  clickPost(){
        var param={"id":1,"username":"张三","sex":"男"};
        //发起异步请求
        $.ajax({
            type:"post",
            data:JSON.stringify(param),
            url:"/json/testPost",
            contentType: "application/json",
            success:function (data){
                alert(data)
            },
            error:function (data){
                console.log("失败了")
            }

        });
    }
</script>
</html>